package cn.openea.perpartner.meily.web.controller;

import cn.openea.perpartner.common.core.web.controller.BaseController;
import cn.openea.perpartner.common.core.web.domain.AjaxResult;
import cn.openea.perpartner.common.core.web.page.TableDataInfo;
import cn.openea.perpartner.meily.web.entity.LearningCourse;
import cn.openea.perpartner.meily.web.entity.vo.CourseSeSearchVo;
import cn.openea.perpartner.meily.web.entity.vo.CourseVo;
import cn.openea.perpartner.meily.web.service.ILearningCourseService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * 学习课程
 *
 * @author ysk
 * @email zane_ysk@qq.com
 * @date 2023-06-25 17:03:56
 */
@RestController
@RequestMapping("/learning/course")
public class LearningCourseController extends BaseController {

    @Resource
    private ILearningCourseService learningCourseService;

    @ApiOperation("视频列表-分页")
    @GetMapping("/page/list")
    public TableDataInfo pageList(CourseSeSearchVo searchVo) {
        startPage();
        List<LearningCourse> courseList = learningCourseService.selectList(searchVo);
        return getDataTable(courseList);
    }

    @ApiOperation("课程详情")
    @GetMapping("/get/{id}")
    public AjaxResult selectCourseInfo(@PathVariable Long id) {
        LearningCourse learningCourse = learningCourseService.getById(id);
        return AjaxResult.success(learningCourse);
    }

    @ApiOperation("上架课程")
    @PostMapping("/shelf/{id}")
    public AjaxResult shelfCourse(@PathVariable Long id) {
        return toAjax(learningCourseService.shelfCourse(id));
    }

    @ApiOperation("下架课程")
    @PostMapping("/down/{id}")
    public AjaxResult downCourse(@PathVariable Long id) {
        return toAjax(learningCourseService.downCourse(id));
    }

    @ApiOperation("置顶课程")
    @PostMapping("/top/{id}")
    public AjaxResult topCourse(@PathVariable Long id) {
        return toAjax(learningCourseService.topCourse(id));
    }

    @ApiOperation("取消课程")
    @PostMapping("/top/cancel/{id}")
    public AjaxResult cancelTopCourse(@PathVariable Long id) {
        return toAjax(learningCourseService.cancelTopCourse(id));
    }

    @ApiOperation("新增课程")
    @PostMapping("/add")
    public AjaxResult addCourse(@RequestBody CourseVo courseVo) {
        learningCourseService.addCourse(courseVo);
        return AjaxResult.success();
    }

    @ApiOperation("修改课程")
    @PostMapping("/edit")
    public AjaxResult update(@RequestBody CourseVo courseVo) {
        learningCourseService.editCourse(courseVo);
        return AjaxResult.success();
    }


    @ApiOperation("删除课程")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody List<Long> idList) {
        return success(this.learningCourseService.removeByIds(idList));
    }

}
